@extends('admin.layout.layout', ['row' => @$page])
@php
    $deleteRight = checkMethodsAuthority('roll_delete');

@endphp

@section('contain')



    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
            <!--<div class="item">
                    <a href="/admin/download?a=rolls_distribution&b=template" class="btn btn-primary">{{ ts('DOWNLOADDISTTEMPLATE') }}</a>
                </div>
                <div class="item">
                    <a href="/admin/rolls/importDistribution" class="btn btn-primary">{{ ts('BULKDISTIMPORT') }}</a>
                </div>-->
                @if(checkMethodsAuthority('rolls_import'))
                    <!--<div class="item">
                        <a href="/admin/download?a=rolls&b=template" class="btn btn-primary">{{ ts('DOWNLOADTEMPLATE') }}</a>
                    </div>
                    <div class="item">
                        <a href="/admin/rolls/import" class="btn btn-primary">{{ ts('BULKIMPORT') }}</a>
                    </div>-->
                @endif
                @if(checkMethodsAuthority('rolls_create') && 0)
                    <!--<div class="item">
                        <a href="/{{ request()->path() }}/create" class="btn btn-primary">{{ ts('addnew') }}</a>
                    </div>-->
                @endif
            </div>
        </div>

        <div class="panel-tab">
            <a href="?t=1" class="btn {{ request()->input('t') !=2 && request()->input('t') !=3 ? 'btn-danger' : 'btn-primary' }} mx-3">膜卷</a>
            <a href="?t=2" class="btn {{ request()->input('t') ==2 ? 'btn-danger' : 'btn-primary' }} mx-3">套件</a>
            <a href="?t=3" class="btn {{ request()->input('t') ==3 ? 'btn-danger' : 'btn-primary' }} mx-3">套餐</a>
        </div>

        <div class="filter-wrapper">
            <form action="/{{ request()->path() }}/" class="form-inline filter-form">
                <div class=" input-group mb-3 custom-control-inline">
                    <input type="text" class="form-control s-input" name="value" value="{{ request()->input('value') }}" placeholder="请输入卷号">
                </div>
                @if (empty($user_type) || !in_array($user_type, [2, 4]))
                    <x-p-f-select></x-p-f-select>
                @else
                    <div class="input-group mb-3 custom-control-inline">
                        <div class="input-group-prepend">
                            <span class="input-group-text">{{ @$label ?: ts('PRODUCTTYPE') }}</span>
                        </div>
                        <select name="product_type_id" class="form-control sd_product_filmtype" style="width: 150px" data-value="{{ request()->input('product_type_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            @foreach(\App\Models\ProductTypes::orderBy('id')->get('id') as $v)
                                <option value="{{ $v->id }}" {{ request()->input('product_type_id')==$v->id ? 'selected' : '' }}>{{ ts('product_types.'.$v->id) }}</option>
                            @endforeach
                        </select>
                    </div>

                    <div class="input-group mb-3 custom-control-inline">
                        <div class="input-group-prepend">
                            <span class="input-group-text">{{ @$label ?: ts('MXH') }}</span>
                        </div>
                        <select name="film_type_id" class="form-control sd-filmtype" style="width: 150px" data-value="{{ request()->input('film_type_id') }}">
                            <option value="">{{ ts('select') }}</option>
                        </select>
                    </div>
                @endif

                <div class="mb-3">
                    <button class="btn btn-primary">{{ ts('SEARCH') }}</button>
                    <a href="/{{ request()->path() }}/" class="btn btn-warning">{{ ts('RESET') }}</a>
                </div>
            </form>
        </div>
        <div>
            <div>
                <table class="table text-nowrap bt-table d-none text-center">
                    <thead>
                    <tr class="order_column text-center">
                        <th data-column="id" style="width: 80px">{{ ts('SEQUENCE') }}</th>
                        <th data-column="roll_number" style="width: 150px">{{ ts('rollnumber') }}</th>
                        <th data-column="film_type_id" style="width: 150px">{{ ts('FILMTYPE') }}</th>
                        <th>{{ ts('SYKSYCD') }}</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $k => $v)
                        @php
                            $vRestlen = @$v->restlen ?: 0;
                            $Restlen =  getRestlenV301($v->roll_number) ?: 0;
                        @endphp
                        <tr class="item-list">
                            <td>
                                {{ @$data->firstItem()+$k }}
                            </td>
                            <td>
                                {{ @$v->roll_number }}
                            </td>

                            <td>
                                {{ ts('film_type_master.'.$v->film_type_id) }}
                            </td>

                            <td>
                                {{ $vRestlen }}  cm
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
            <div class="text-right my-3">
                <span class="alert alert-primary d-inline-block mb-0">
                    {{ ts('rollsalesstatistics') }}：
                    <span class="text-danger" style="font-weight: bold;letter-spacing: .4px">{{ (@$total/100) }} m</span>
                    {{--<span class="text-danger roll-saless-tatistics"></span>--}}
                </span>
            </div>
            <div class="row my-3">
                <div class="col">
                    {{ $data->appends(request()->input())->links() }}
                </div>
            </div>
        </div>


    </div>


@endsection


@section('script')
    <script>
        $(document).ready(function () {
            $('.table.bt-table').bootstrapTable({
                fixedColumns: true,
                fixedNumber: 1,
                fixedRightNumber: 1,
            }).removeClass('d-none')
        });

        @if (!empty($user_type) && in_array($user_type, [2, 4]))
        $(function () {
            @if (request()->input('product_type_id'))
            request.get('/admin/rolls/getRollsType', {
                params: {
                    product_id: '{{ request()->input('product_type_id') }}',
                }
            })
                .then( function(d) {
                    console.log(d);
                    var data = d.data
                })
                .catch(function (d) {
                    let html = '<option value="">请选择</option>';
                    if (d && d.length > 0) {
                        for (let i in d) {
                            if (d == '' || d[i] == '' || typeof d[i]['id'] == 'undefined') {
                                continue;
                            }
                            html += '<option value="' + d[i]['id'] + '"';
                            @if (request()->input('film_type_id'))
                            if (d[i]['id'] == '{{ request()->input('film_type_id') }}') {
                                html += ' selected ';
                            }
                            @endif
                                html += '>' + d[i]['value'] + '</option>';
                        }
                    }
                    $(".sd-filmtype").empty().append(html);
                })
            @endif

            $(".sd_product_filmtype").on("change", function () {
                console.log($(this).val());
                let product_id = $(this).val();
                if (product_id == '' || typeof product_id == 'undefined') {
                    $(".sd-filmtype").empty().append('<option value="">请选择</option>');
                    return;
                }
                request.get('/admin/rolls/getRollsType', {
                    params: {
                        product_id: product_id,
                    }
                })
                    .then( function(d) {
                        console.log(d);
                        var data = d.data
                        $('.portlet select[name="user_id"]').empty().append(makeSelectOptionsOnly(data))
                    })
                    .catch(function (d) {
                        let html = '<option value="">请选择</option>';
                        if (d && d.length > 0) {
                            for (let i in d) {
                                if (d == '' || d[i] == '' || typeof d[i]['id'] == 'undefined') {
                                    continue;
                                }
                                html += '<option value="' + d[i]['id'] + '">' + d[i]['value'] + '</option>';
                            }
                        }
                        $(".sd-filmtype").empty().append(html);
                    })
            });
        });
        @endif
    </script>
@endsection